﻿package mortal.game.view.mainUI.smallMap
{
    import com.fyGame.fyMap.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.text.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.common.net.*;
    import mortal.component.window.*;
    import mortal.game.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.*;
    import mortal.game.scene3D.player.entity.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.petBreak.*;
    import mortal.game.view.mainUI.smallMap.view.*;
    import mortal.game.view.wizard.*;
    import mortal.mvc.core.*;

    public class SmallMapModule extends BaseWindow
    {
        private var _tab:GTabarNew;
        private var _curMapContainer:GSprite;
        private var _world:SmallMapWorldRegion;
        private var _region:SmallMapWorldRegion;
        private var _image:SmallMapImage;
        private var _rightBg:ScaleBitmap;
        private var _rightTop:SmallMapRightTop;
        private var _rightDown:SmallMapRightDown;
        private var _pathShower:SmallMapPathShower;
        private var _typeShower:SmallMapTypeShower;
        private var _customWin:SmallMapCustomMapPointWin;
        private var _curXYBg:ScaleBitmap;
        private var _xy:GTextFiled;
        private var _mapName:String = "";
        private var _curScale:Number;
        private var _txtRelocateTips:GTextFiled;
        private var _tabData:Array;
        private var _tobeIndex:int = 0;
        public static var _mapInfo:FyMapInfo;

        public function SmallMapModule()
        {
            this._tabData = [{name:0, label:Language.getString(20124)}, {name:1, label:Language.getString(20125)}];
            setSize(726, 570);
            this.title = Language.getString(20023);
            this.titleHeight = 60;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            var _loc_4:GMapInfo = null;
            super.createDisposedChildrenImpl();
            var _loc_1:* = this._tabData.concat();
            var _loc_2:* = Cache.instance.role.roleInfo.level;
            if (_loc_2 >= 30)
            {
                _loc_1.push({name:2, label:Language.getString(21325)});
                _loc_4 = GameMapConfig.instance.getMapInfo(90011);
                if (_loc_4 != null && _loc_2 <= 54)
                {
                    _loc_1.push({name:3, label:Language.getString(21326)});
                }
            }
            this._tab = UIFactory.gTabBarNew(4, 32, _loc_1, 723, 570, 72, 24, this, this.tabBarChangeHandler, "TabButtonNew");
            this._world = UICompomentPool.getUICompoment(SmallMapWorldRegion) as SmallMapWorldRegion;
            this._world.x = 14;
            this._world.y = 105;
            this._region = UICompomentPool.getUICompoment(SmallMapWorldRegion) as SmallMapWorldRegion;
            this._region.x = 14;
            this._region.y = 105;
            this._curMapContainer = UICompomentPool.getUICompoment(GSprite) as GSprite;
            this.addChild(this._curMapContainer);
            this._curMapContainer.mouseChildren = true;
            this._curMapContainer.mouseEnabled = true;
            this._image = UICompomentPool.getUICompoment(SmallMapImage) as SmallMapImage;
            this._image.x = 10;
            this._image.y = 65;
            this._curMapContainer.addChild(this._image);
            this._rightBg = UIFactory.bg(this._image.x + 504, this._image.y, 202, 500, this._curMapContainer, ImagesConst.PanelBg);
            this._rightTop = UICompomentPool.getUICompoment(SmallMapRightTop) as SmallMapRightTop;
            this._rightTop.x = this._rightBg.x;
            this._rightTop.y = this._rightBg.y;
            this._curMapContainer.addChild(this._rightTop);
            this._rightDown = UICompomentPool.getUICompoment(SmallMapRightDown) as SmallMapRightDown;
            this._rightDown.x = this._rightTop.x;
            this._rightDown.y = this._rightTop.y + 244;
            this._curMapContainer.addChild(this._rightDown);
            this._pathShower = UICompomentPool.getUICompoment(SmallMapPathShower) as SmallMapPathShower;
            this._pathShower.x = this._image.x;
            this._pathShower.y = this._image.y;
            this._typeShower = UICompomentPool.getUICompoment(SmallMapTypeShower) as SmallMapTypeShower;
            this._typeShower.x = this._pathShower.x;
            this._typeShower.y = this._pathShower.y;
            this._curMapContainer.addChild(this._typeShower);
            this._curMapContainer.addChild(this._pathShower);
            this._curXYBg = UIFactory.bg(this._image.x + 10, this._image.y + 6, 158, 26, this._curMapContainer, ImagesConst.PanelBg);
            var _loc_3:* = GlobalStyle.textFormatLv;
            _loc_3.align = TextFormatAlign.CENTER;
            _loc_3.size = 13;
            this._xy = UIFactory.gTextField("", this._curXYBg.x, this._image.y + 7, this._curXYBg.width, 20, this._curMapContainer, _loc_3);
            _loc_3 = _loc_3.clone();
            _loc_3.color = 16776960;
            _loc_3.size = 12;
            _loc_3.align = TextFormatAlign.RIGHT;
            this._txtRelocateTips = UIFactory.gTextField("", this._curXYBg.x + 120, this._image.y + 9, 368, 20, this._curMapContainer, _loc_3);
            this._txtRelocateTips.mouseEnabled = false;
            return;
        }// end function

        public function changeToWorld(param1:Array) : void
        {
            this._txtRelocateTips.text = "";
            if (this._tab.selectedIndex != 0)
            {
                this._tab.selectedIndex = 0;
            }
            DisplayUtil.removeMe(this._curMapContainer);
            DisplayUtil.removeMe(this._region);
            this.addChild(this._world);
            this._world.updateAll(param1);
            return;
        }// end function

        public function changeToRegion(param1:Array) : void
        {
            this._txtRelocateTips.text = "";
            if (this._tab.selectedIndex != 0)
            {
                this._tab.selectedIndex = 0;
            }
            DisplayUtil.removeMe(this._world);
            DisplayUtil.removeMe(this._curMapContainer);
            this.addChild(this._region);
            this._region.updateAll(param1);
            return;
        }// end function

        public function isShowingAutoFightMap() : Boolean
        {
            return this._tab.selectedIndex == 2 || this._tab.selectedIndex == 3;
        }// end function

        public function isShowingCurMap() : Boolean
        {
            return this._tab.selectedIndex == 1;
        }// end function

        public function changeToCur() : void
        {
            this._txtRelocateTips.text = "";
            if (this._tab.selectedIndex != 1)
            {
                this._tab.selectedIndex = 1;
            }
            DisplayUtil.removeMe(this._world);
            DisplayUtil.removeMe(this._region);
            this.addChild(this._curMapContainer);
            return;
        }// end function

        public function changeToAutoFight() : void
        {
            if (this._tab.selectedIndex != 2 && this._tab.selectedIndex != 3)
            {
                this._tab.selectedIndex = 2;
            }
            this._txtRelocateTips.text = Language.getString(21327);
            DisplayUtil.removeMe(this._world);
            DisplayUtil.removeMe(this._region);
            this.addChild(this._curMapContainer);
            return;
        }// end function

        public function get rightTop() : SmallMapRightTop
        {
            return this._rightTop;
        }// end function

        public function get rightDown() : SmallMapRightDown
        {
            return this._rightDown;
        }// end function

        public function get typeShower() : SmallMapTypeShower
        {
            return this._typeShower;
        }// end function

        public function get pathShower() : SmallMapPathShower
        {
            return this._pathShower;
        }// end function

        public function changeToTab(param1:int = 2) : void
        {
            this._tobeIndex = param1;
            CallLater.addCallBack(this.nextFrame);
            return;
        }// end function

        private function nextFrame() : void
        {
            this._tab.selectedIndex = this._tobeIndex;
            this.tabBarChangeHandler(null);
            return;
        }// end function

        public function updateSelfXY() : void
        {
            var _loc_1:* = PetBreakCopyUtil.player;
            var _loc_2:* = _loc_1.x2d;
            var _loc_3:* = _loc_1.y2d;
            this._xy.text = this._mapName + " (" + _loc_2.toString() + ", " + _loc_3.toString() + ")";
            this._pathShower.updateSelfPlace(_loc_2 * this._curScale, _loc_3 * this._curScale);
            return;
        }// end function

        public function showHideCustomXYWin(param1:Array) : void
        {
            if (this._customWin != null && !this._customWin.isHide)
            {
                this._customWin.hide();
                return;
            }
            if (this._customWin == null)
            {
                this._customWin = UICompomentPool.getUICompoment(SmallMapCustomMapPointWin) as SmallMapCustomMapPointWin;
                this._customWin.layer = this;
                this._customWin.x = 727;
                this._customWin.y = 301;
            }
            this._customWin.show(727, 301);
            this._customWin.updateData(param1);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._tab.dispose(param1);
            this._tab = null;
            this._curMapContainer.dispose(param1);
            this._curMapContainer = null;
            this._world.dispose(param1);
            this._world = null;
            this._region.dispose(param1);
            this._region = null;
            this._image.dispose(param1);
            this._image = null;
            this._rightBg.dispose(param1);
            this._rightBg = null;
            this._pathShower.dispose(param1);
            this._pathShower = null;
            this._rightDown.dispose(param1);
            this._rightDown = null;
            this._rightTop.dispose(param1);
            this._rightTop = null;
            this._typeShower.dispose(param1);
            this._typeShower = null;
            if (this._customWin != null)
            {
                this._customWin.dispose(param1);
                this._customWin = null;
            }
            this._curXYBg.dispose(param1);
            this._curXYBg = null;
            this._xy.dispose(param1);
            this._xy = null;
            this._txtRelocateTips.dispose(param1);
            this._txtRelocateTips = null;
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show();
            this.updateToMap(Game.mapInfo);
            if (Cache.instance.group.isInGroup)
            {
                GameProxy.group.getMembersPlaces();
            }
            if (CopyUtil.isInCopy)
            {
                Cache.instance.autoFight.updateBossKilled();
            }
            return;
        }// end function

        public function getShowingMapInfo() : FyMapInfo
        {
            return _mapInfo;
        }// end function

        public function updateToMap(param1:FyMapInfo) : void
        {
            _mapInfo = param1;
            if (_mapInfo == null)
            {
                return;
            }
            this.updateCurScale();
            var _loc_2:* = GameMapConfig.instance.getMapInfo(_mapInfo.mapId);
            if (_loc_2 != null)
            {
                this._mapName = _loc_2.name;
            }
            else
            {
                this._mapName = "宝爷配置地图名字";
            }
            this._image.load(_mapInfo, this.onLoaded);
            return;
        }// end function

        private function updateCurScale() : void
        {
            this._curScale = DisplayUtil.calculateFixedScale(this._image.bWidth, this._image.bHeight, _mapInfo.gridWidth, _mapInfo.gridHeight);
            return;
        }// end function

        private function onLoaded() : void
        {
            if (isDisposed)
            {
                return;
            }
            this._pathShower.x = this._image.x + this._image.dx;
            this._pathShower.y = this._image.y + this._image.dy;
            this._typeShower.x = this._pathShower.x;
            this._typeShower.y = this._pathShower.y;
            this.updateCurScale();
            Dispatcher.dispatchEvent(new DataEvent(EventName.SMallMapImgLoaded, _mapInfo));
            return;
        }// end function

        public function get mapScale() : Number
        {
            return this._curScale;
        }// end function

        public function get curMapId() : int
        {
            return _mapInfo.mapId;
        }// end function

        public function showPathPoints(param1:Array) : void
        {
            this._pathShower.showPath(param1, this._curScale, this._curScale);
            return;
        }// end function

        public function clearPaths() : void
        {
            this._pathShower.clearPaths();
            return;
        }// end function

        override public function set width(param1:Number) : void
        {
            this._image.myWidth = param1;
            return;
        }// end function

        override public function set height(param1:Number) : void
        {
            this._image.myHeight = param1;
            return;
        }// end function

        private function tabBarChangeHandler(param1) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.SmallMapChangeTab, this._tab.selectedIndex));
            return;
        }// end function

    }
}
